package jp.co.tms.internal.runserver.protocol;

import jp.co.tms.internal.util.NumberUtil;

public abstract class CommandPackage extends Package implements ICommandPackage {

	private int _id ;
	
	public CommandPackage( int type, int id ) {
		super(type);
		this._id = id ;
	}
	
	public int getId() {
		return _id;
	}
	
	public void setId(int id) {
		this._id = id;
	}

	public byte[] getBytes( byte[] data ){
	
		byte[] buffer = null ;
		if ( data != null && data.length != 0 ){
			buffer = new byte[data.length + SYS_INT_SIZE] ;
			System.arraycopy( data,
					0, 
					buffer, 
					SYS_INT_SIZE, 
					data.length
					);
		}
		else {
			buffer = new byte[SYS_INT_SIZE];
		}
		
		byte[] values = NumberUtil.intToByteArray( _id ) ;
		System.arraycopy( values, 
				0, 
				buffer, 
				0, 
				SYS_INT_SIZE 
				) ;
		
		return super.getBytes( buffer );
	}
}
